$(function () {
    var user = null, html = [], thisPage = null;

    activateCardPage = function () {
        this.init();
    };
    activateCardPage.prototype = {
        init: function () {
            this.initData();
            this.bindEvent();
        },
        initData: function () {
            user = getLocalStorage(STORAGE_MANAGER.user);
            if (!user || !user.id) {
                redirect("../account/login.html");
                return false;
            }

        },
        bindEvent: function () {
            //后退
            $("#back").on("tap", function () {
                back();
            });
            //清除输入
            $("#clear").on("tap", function () {
                $("input").val("");
            });
            $("#card_no,#password").on("input", function () {

                if ("" == $("#card_no").val() ||
                    "" == $("#password").val()) {
                    $("#activenow").addClass("gray_color").unbind();
                } else {
                    $("#activenow").removeClass("gray_color").unbind().on("tap", function () {
                        var requestData = {
                            "coupon_token": $("#card_no").val(),
                            "password": $("#password").val()
                        };
                        $.ajax({
                            type: "POST",
                            url: CONFIG_MANAGER.RequstUrl + "v1/member/asset/gift/" + user.id,
                            async: true,
                            contentType: 'application/json',
                            headers: {"token": user.token},
                            data: JSON.stringify(requestData),
                        }).done(function (data) {
                            $.alert("激活成功", function () {
                                redirect("../mine/mylife.html");
                                return false;
                            });
                        }).fail(function (data) {
                            var infor = JSON.parse(data);
                            $.alert(infor.message);
                        });
                    });
                }
            });
            //现金充值余额钱包
            $("#charge").on("tap", function () {
                redirect("walletRecharge.html");
                return false;
            });
        }
    };

    thisPage = new activateCardPage();
});
